package main

import (
	"fmt"
)

type Usber interface {
	start()
	stop()
}

type Computer struct {
}

func (c Computer) work(usb Usber) {
	switch usb.(type) {
	case Phone:
		_, ok := usb.(Phone)
		fmt.Println(ok)
		usb.start()
	case Camera:
		_, ok := usb.(Camera)
		fmt.Println(ok)
		usb.stop()
	default:
		panic("错误")
	}
}

type Phone struct {
	Name string
}

func (p Phone) start() {
	fmt.Println(p.Name, "手机启动")
}

func (p Phone) stop() {
	fmt.Println(p.Name, "手机关机")
}

type Camera struct {
	Name string
}

func (c Camera) start() {
	fmt.Println(c.Name, "相机启动")
}

func (c Camera) stop() {
	fmt.Println(c.Name, "相机关机")
}

func main() {
	p := Phone{
		Name: "Huawei",
	}

	c := Camera{
		Name: "Apple",
	}

	computer := Computer{}
	computer.work(p)
	computer.work(c)
}
